<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>管理员页面</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<div class="layui-row layui-col-space15">
    <form class="layui-form">
        <blockquote class="layui-elem-quote">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请医生姓名" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </blockquote>
    </form>
    <table id="doctors" lay-filter="doctors"></table>
</div>
<script type="text/html" id="MessageToolBar">
    <a class="layui-btn layui-btn-xs layui-bg-orange" lay-event="mes"><i class="layui-icon">&#xe611;</i>留言</a>
</script>
</body>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table','form','jquery','laypage'],function () {
        var form = layui.form,
            table = layui.table,
            page = layui.laypage,
            $ = layui.jquery;

        //医生信息数据
        var doctors = table.render({
            elem: "#doctors",
            url: '/admin/listDoctor',
            limit: 5,
            limits: [5, 10, 15, 20, 25],
            page: true,
            loading:true,
            response: {
                statusName: 'code'
                , statusCode: 200
                , msgName: 'msg'
                , countName: 'count'
                , dataName: 'data'
            },
            id: 'doctors',
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'id', title: 'ID', width: 60, align: "center"},
                {field: 'docName', title: '医生姓名', width:200, align: 'center'},
                {field:'docSex', title:'性别',width:80, align: 'center'},
                {field:'docTel', title:'联系方式',width:350, align: 'center'},
                {field:'docDate',title:'出生年月', align: 'center'},
                {field:'docTitle',title:'职称',width:200, align: 'center'},
                {title:'操作',templet:'#MessageToolBar',fixed: "right",width:120,align:'center'}
            ]]
        });

        /**
         * 监听表格工具按钮事件 普通用户列表
         */
        table.on('tool(doctors)',function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            console.log(data);
            if (layEvent === 'mes'){//监听修改
               mes(data.id);
            }
        });


        /**
         * 患者留言
         * @param did
         */
        function mes(did){
            console.log(did);
            var index = layui.layer.open({
                title : "患者留言",
                type : 2,
                area:['30%','30%'],
                content : "./message_window.html",
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    if(did != null){
                        body.find(".doctorNo").val(did);
                        form.render();
                    }
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },1000)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域
            $(window).on("resize",function(){
                layui.layer.full(index);
            });
        }



        /**
         * 查询
         */
        $('.search_btn').click(function () {
            if($(".searchVal").val() != ''){
                var index = top.layer.msg('数据查询中，请稍候',{icon: 16,time:false,shade:0.8});
                table.reload("doctors",{
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        docName : $(".searchVal").val(), //搜索的关键字
                    },
                });
                top.layer.close(index);
            }else{
                layer.msg("请输入医生姓名");
            }
        });


    });

</script>
</html>